package com.zry.controller.archives;

import com.zry.VO.ArticleYearVo;
import com.zry.service.archives.IArchivesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

@Controller
public class ArchivesController {


    @Autowired
    private IArchivesService archivesService;


    /**
     * 归档首页
     *
     * @return
     */
    @GetMapping(value = {"/archives", "/acv"})
    public ModelAndView toArchives() {
        // 1: 创建modelandview实例
        ModelAndView modelAndView = new ModelAndView();
        // 2: 指定返回的页面视图
        modelAndView.setViewName("archives/index");
        // 3: 返回
        return modelAndView;
    }

    @GetMapping("/api/archives/load")
    @ResponseBody
    public List<ArticleYearVo> findArticleByYear(){
        return archivesService.findBlogByYear();
    }

    @GetMapping("/api/archives/loadMore")
    @ResponseBody
    public  List<Map<String, Object>> loadMore(Integer year,
                                               @RequestParam(defaultValue = "1") Integer pageNo,
                                               @RequestParam(defaultValue = "1") Integer pageSize){
        return archivesService.findBlogByPageNo(year,pageNo,pageSize);
    }

    /**
     * 分割线
     * =============================================================================================
     * 以下方法都是 文章归档测试使用
     * @return
     */

    @GetMapping(value = {"/archivesTest", "/acvTest"})
    public ModelAndView toArchivesTest() {
        // 1: 创建modelandview实例
        ModelAndView modelAndView = new ModelAndView();
        // 2: 指定返回的页面视图
        modelAndView.setViewName("archives/archive");
        // 3: 返回
        return modelAndView;
    }

    @GetMapping("/api/archivesTest/load")
    @ResponseBody
    public List<Map<String, Object>> queryBlog(){
        return archivesService.queryBlog();
    }

    @GetMapping("/api/archivesTest/load2")
    @ResponseBody
    public List<ArticleYearVo> queryBlog2(){
        return archivesService.queryBlog2();
    }

    @GetMapping("/api/archivesTest/load3")
    @ResponseBody
    public List<Map<String, Object>> queryBlog3(){
        return archivesService.findBlogGroupByYear();
    }


}